<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.*"%>
<%@ page import="org.apache.commons.fileupload.disk.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%
    request.setCharacterEncoding("UTF-8");    
    String uploadPath = "E:\\temp";
    File uploadfile = new File(uploadPath);
    if(!uploadfile.exists()){         
        uploadfile.mkdirs();         
    } 
    String path = request.getContextPath();
    String strfilename="";
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (isMultipart == true) {
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<FileItem> items = upload.parseRequest(request);//得到所有的文件
            System.out.println("个数："+items.size());
            Iterator<FileItem> itr = items.iterator();
            while (itr.hasNext()) {//依次处理每个文件
                FileItem item = (FileItem) itr.next();
                String fileName = item.getName();//获得文件名，包括路径
                if (fileName != null) {
                    File fullFile = new File(item.getName());
                    File savedFile = new File(uploadPath, fullFile.getName());
                    strfilename = fullFile.getName();
                    item.write(savedFile);
                }
                //System.out.println("1---------------{success:true,message:'上传成功'}");
                //response.resetBuffer();
                //response.getWriter().print("{success:true,message:'上传成功'}"); 
            }
            System.out.println("{2--------------success:true,message:'上传成功'}");
            response.resetBuffer();
            //response.reset();
            //response.getWriter().print("{success:true,message:'上传成功'}"); 
            out.print("{success:true,message:'上传成功'}");
        }
        catch (Exception e) {
            e.printStackTrace();
            //response.resetBuffer();
            //System.out.println("3-----------{success:true,message:'上传成功'}");
        }
    }
    else {
        //System.out.println("4----------------------{success:true,message:'上传成功'}");
        //response.resetBuffer();
        //response.getWriter().print("{success:true,message:'上传成功'}");
    }
%>
